updating oE format

format

include datetime.e -- (default namespace is datetime) 
public function format(datetime d, sequence pattern = "%Y-%m-%d %H:%M:%S") 

Formats the date according to the format pattern string.

Parameters:
  1. d : a datetime which is to be printed out
  2. pattern : a format string, similar to the ones sprintf uses, but with some Unicode encoding. The default is "%Y-%m-%d %H:%M:%S".
Returns:

A string, with the date d formatted according to the specification in pattern.

Comments:

Pattern string can include the following specifiers:

  • %% -- a literal %
  • %a -- locale's abbreviated weekday name (e.g., Sun)
  • %A -- locale's full weekday name (e.g., Sunday)
  • %b -- locale's abbreviated month name (e.g., Jan)
  • %B -- locale's full month name (e.g., January)
  • %C -- century; like %Y, except omit last two digits (e.g., 21)
  • %d -- day of month (e.g, 01)
  • %H -- hour (00..23)
  • %I -- hour (01..12)
  • %j -- day of year (001..366)
  • %k -- hour ( 0..23)
  • %l -- hour ( 1..12)
  • %m -- month (01..12)
  • %M -- minute (00..59)
  • %p -- locale's equivalent of either AM or PM; blank if not known
  • %P -- like %p, but lower case
  • %s -- seconds since 1970-01-01 00:00:00 UTC
  • %S -- second (00..60)
  • %u -- day of week (1..7); 1 is Monday
  • %w -- day of week (0..6); 0 is Sunday
  • %y -- last two digits of year (00..99)
  • %Y -- year
Note:

There is a format() function in std/text.e as well. Be sure to use the proper namespace if using both std/datetime.e and std/text.e

Example 1:
include std/datetime.e 
 
datetime d = new(2008, 5, 2, 12, 58, 32) 
sequence s = format(d, "%Y-%m-%d %H:%M:%S") 
puts(1,s) 
Results:

2008-05-02 12:58:32

Example 2:
include std/datetime.e 
 
datetime d = new(2008, 5, 2, 12, 58, 32) 
sequence s = format(d, "%A, %B %d '%y %H:%M%p") 
puts(1,s) 
Results:

Friday, May 2 '08 12:58PM

See Also:

to_unix, parse

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu